//
//  UIView+Additions.h
//  DJAppModule
//
//  Created by Lynn_Lin on 2018/5/8.
//

#import <UIKit/UIKit.h>

@interface UIView (Additions)
//屏幕截图
- (UIImage *) screenshot;


/**
 Create a snapshot image of the complete view hierarchy.

 @return 返回一个新的图片，有可能为null
 */
- (nullable UIImage *)dj_snapshotImage;

/**
 Create a snapshot image Ddata of the complete view hierarchy.
 
 @return 返回一个新的图片 data，有可能为null
 */
- (nullable NSData *)dj_snapshotData;

/**
 Create a snapshot image of the complete view hierarchy.
 @discussion It's faster than "snapshotImage", but may cause screen updates.
 See -[UIView drawViewHierarchyInRect:afterScreenUpdates:] for more information.
 */
- (nullable UIImage *)dj_snapshotImageAfterScreenUpdates:(BOOL)afterUpdates;

/**
 Create a snapshot image data of the complete view hierarchy.
 @discussion It's faster than "snapshotImage", but may cause screen updates.
 See -[UIView drawViewHierarchyInRect:afterScreenUpdates:] for more information.
 */
- (nullable NSData *)dj_snapshotDataAfterScreenUpdates:(BOOL)afterUpdates;


/**
 给view设置圆角

 @param radius 圆角半径
 @param corners 指定圆角方形
 */
- (void)dj_setViewMaskWithRadius:(CGFloat)radius byRoundingCorners:(UIRectCorner)corners;


/**
 快捷设置view.layer阴影属性

 @param color 阴影颜色
 @param offset 偏移大小
 @param radius 阴影圆角
 */
- (void)dj_setLayerShadow:(nullable UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius;


/**
 将point从当前的view的坐标系转换为view/window的坐标系

 @param point point
 @param view 要转换的成那个坐标系view
 @return 返回 point
 */
- (CGPoint)dj_convertPoint:(CGPoint)point toViewOrWindow:(nullable UIView *)view;

/**
 将point从给定的view/window的坐标系转换为接收view的坐标系

 @param point poing
 @param view 指定的view
 @return 返回接收view的坐标系
 */
- (CGPoint)dj_convertPoint:(CGPoint)point fromViewOrWindow:(nullable UIView *)view;


/**
 将rect从当前的view的坐标系转换为基于view/window的坐标系

 @param rect rect
 @param view 要转换的成那个坐标系view
 @return 返回 rect
 */
- (CGRect)dj_convertRect:(CGRect)rect toViewOrWindow:(nullable UIView *)view;


/**
 将rect从给定的view/window的坐标系转换为接收view的坐标系

 @param rect rect
 @param view 指定的view
 @return 返回 rect
 */
- (CGRect)dj_convertRect:(CGRect)rect fromViewOrWindow:(nullable UIView *)view;


/**
 * Finds the first descendant view (including this view) that is a member of a particular class.
 */
- (UIView*)descendantOrSelfWithClass:(Class)cls;

/**
 * Finds the first ancestor view (including this view) that is a member of a particular class.
 */
- (UIView*)ancestorOrSelfWithClass:(Class)cls;

/**
 * Removes all subviews.
 */
- (void)removeAllSubviews;


/**
 * The view controller whose view contains this view.
 */
- (UIViewController*)viewController;


-(void)removeAllSubViews;


// DRAW GRADIENT
+ (void)drawGradientInRect:(CGRect)rect withColors:(NSArray*)colors;
+ (void)drawLinearGradientInRect:(CGRect)rect colors:(CGFloat[])colors;


// DRAW ROUNDED RECTANGLE
+ (void)drawRoundRectangleInRect:(CGRect)rect withRadius:(CGFloat)radius;

// DRAW LINE
+ (void)drawLineInRect:(CGRect)rect red:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
+ (void)drawLineInRect:(CGRect)rect colors:(CGFloat[])colors;
+ (void)drawLineInRect:(CGRect)rect colors:(CGFloat[])colors width:(CGFloat)lineWidth cap:(CGLineCap)cap;

// FILL RECT
+ (void)drawRect:(CGRect)rect fill:(const CGFloat*)fillColors radius:(CGFloat)radius;
+ (void)drawRect:(CGRect)rect fillColor:(UIColor *)fillColor radius:(CGFloat)radius;

// STROKE RECT
+ (void)strokeLines:(CGRect)rect stroke:(const CGFloat*)strokeColor ;


#pragma mark - UIView frame相关

@property (nonatomic) CGFloat dj_left;        ///<  frame.origin.x.
@property (nonatomic) CGFloat dj_top;         ///<  frame.origin.y
@property (nonatomic) CGFloat dj_right;       ///<  frame.origin.x + frame.size.width
@property (nonatomic) CGFloat dj_bottom;      ///<  frame.origin.y + frame.size.height
@property (nonatomic) CGFloat dj_width;       ///<  frame.size.width.
@property (nonatomic) CGFloat dj_height;      ///<  frame.size.height.
@property (nonatomic) CGFloat dj_centerX;     ///<  center.x
@property (nonatomic) CGFloat dj_centerY;     ///<  center.y
@property (nonatomic) CGPoint dj_origin;      ///<  frame.origin.
@property (nonatomic) CGSize  dj_size;        ///<  frame.size.
@property (nonatomic) CGFloat dj_originY;     ///<  frame.origin.y
@property (nonatomic) CGFloat dj_originX;     ///<  frame.origin.x
@property (nonatomic) CGFloat dj_boundsY;     ///<  bounds.orgin.y


@end
